Infer annotation aesthetics from the active ggplot2 theme (#120)#451
Open
ishaan-arora-1 wants to merge 3 commits intostan-dev:masterfrom
Open
Infer annotation aesthetics from the active ggplot2 theme (#120)#451ishaan-arora-1 wants to merge 3 commits intostan-dev:masterfrom
ishaan-arora-1 wants to merge 3 commits intostan-dev:masterfrom
Conversation
Reference lines (e.g. the vertical zero-line in mcmc_intervals, the rhat=1 line in mcmc_rhat) previously used hardcoded colors like "gray90" that don't adapt when users switch ggplot2 themes. Added an internal annotation_style() helper that reads the active theme's gridline color and linewidth. When gridlines are present, the reference line inherits their color at double the major gridline width. When gridlines are blank (bayesplot's default), it falls back to the previous gray90/0.5 defaults so existing plots are unchanged. Closes stan-dev#120
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #451 +/- ##
==========================================
- Coverage 98.63% 98.52% -0.12%
==========================================
Files 35 35
Lines 5860 5890 +30
==========================================
+ Hits 5780 5803 +23
- Misses 80 87 +7 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
jgabry
requested changes
Mar 11, 2026
Member
jgabry
left a comment
There was a problem hiding this comment.
Thanks @ishaan-arora-1. Just made several review comments.
- Revert geom_ignore() example to keep it simple (no annotation_style call) - annotation_style() now checks panel.grid.major.x / minor.x first, then falls back to panel.grid.major / minor, so themes that only customise vertical gridlines are handled correctly - Accept fallback_color and fallback_linewidth arguments so callers can preserve their original hardcoded defaults when gridlines are blank - Make all diagnostic reference lines in mcmc_rhat() and mcmc_neff() theme-aware (including the dashed break lines, not just the rhat=1 line) - Add unit tests for annotation_style() covering fallback values, theme reading, and panel.grid.major.x preference - Add vdiffr visual tests for mcmc_intervals, mcmc_rhat, and mcmc_neff under theme_gray() to verify theme-aware annotation rendering
Contributor
Author
|
Hey @jgabry how do the changes look now? |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #120.
Reference lines like the vertical zero-line in
mcmc_intervals()and the rhat=1 line inmcmc_rhat()had hardcoded colors ("gray90","gray") that didn't adapt when users switched ggplot2 themes. As @tjmahr pointed out in the issue, this makes them invisible or look wrong on themes liketheme_grey()or dark themes.Added an internal
annotation_style()helper that reads the active theme's gridline color and linewidth to derive sensible reference line aesthetics. When gridlines are blank (bayesplot's default theme), it falls back to the previousgray90/0.5defaults so existing plots look exactly the same.Updated the four internal call sites in
mcmc-intervals.R(3xvline_0) andmcmc-diagnostics.R(1xvline_at) to use the new helper.